﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using Ocmf.Forms;

namespace Ocmf.Types
{
    public class Delay:Action
    {
        private int duration;
        public int Duration
        {
            get
            {
                return duration;
            } 
            set
            {
                duration = value;
                Text = "Delay: " + duration + " Secs";
            }
        }

        public Delay()
        {
            Text = "Delay: " + duration + " Secs";
            ImageKey = SelectedImageKey = "delay";
        }

        public override object Clone()
        {
            var clone = base.Clone() as Delay;
            clone.Duration = Duration;
            return clone;
        }

        public override Form Editor
        {
            get { return new EditDelayForm(this); }
        }

        public override XmlElement ToXml(XmlDocument xmlDocument)
        {
            //create trial xml element
            var buzzerElement = xmlDocument.CreateElement("Delay");
            //create duration attribute
            var durationAttribute = xmlDocument.CreateAttribute("Duration");
            durationAttribute.InnerText = Duration.ToString();
            //add attribute to element
            buzzerElement.Attributes.Append(durationAttribute);
            //return element
            return buzzerElement;
        }

        public override void FromXml(XmlNode xmlElement)
        {
            Duration = int.Parse(xmlElement.Attributes["Duration"].InnerText);
        }
    }
}
